package com.bjpowernode.utils.converter;

import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.data.WriteCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.bjpowernode.config.context.ApplicationContextProvider;
import com.bjpowernode.constant.Constants;
import com.bjpowernode.service.TDicValueService;

import java.util.Map;

/**
 *
 */
public class IntentionStateConverter implements Converter<Integer> {

    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        // 获取spring的bean
        TDicValueService tDicValueService = ApplicationContextProvider.getApplicationContext().getBean(TDicValueService.class);
        // 获取全部数据
        Map<String, Integer> stringIntegerMap = tDicValueService.selectAllNameAndIdByClueState(Constants.INTENTION_STATE);
        // 获取转换数据
        String stringValue = cellData.getStringValue();
        return stringIntegerMap.get(stringValue);
    }

    @Override
    public WriteCellData<?> convertToExcelData(Integer value, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        switch (value) {
            case 46 -> {
                return new WriteCellData<>("有意向");
            }
            case 47 -> {
                return new WriteCellData<>("无意向");
            }
            default -> {
                return new WriteCellData<>("意向不明");
            }
        }
    }
}
